package reflect;

import java.util.Scanner;

/**
 * 加载Person类的类对象
 * 通过类对象输出:
 * 1:类的完全限定名
 * 2:仅类名
 * 3:仅包名
 */
public class Test {
    public static void main(String[] args) {
//        Class cls = Person.class;
//        String name = cls.getName();
//        System.out.println(name);
//
//        name = cls.getSimpleName();
//        System.out.println(name);
//
//        Package pack = cls.getPackage();
//        System.out.println(pack.getName());

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入类名");
        String className = sc.nextLine();
        Class cls = null;
        try {
            cls = Class.forName(className);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        System.out.println(cls.getName());
        className = cls.getSimpleName();
        System.out.println(className);

        Package pack = cls.getPackage();
        className = pack.getName();
        System.out.println(className);


    }
}
